/**
 * The class keeps the constant parameters used by the project. 
 * All parameters are stored in the xml document, and they could 
 * be configured by the users without recompiling the program. 
 */
package qy.course.cse494.config;

import java.io.File;

import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * @author yqi
 */
public class ConfigureCenter
{
	static final String _cfg_location = "data/ConfigureCenter.xml";
	
	static boolean _is_debugged;
	
	static double _tfidf_constant_tf_1 = 0.5f;
	static double _tfidf_constant_tf_2 = 0.5f;
	static double _tfidf_constant_idf_1 = 0f;
	static boolean _tfidf_is_normalized = true;
	
	static int _search_hit_number_per_page = 10;
	
	static //Do the very initiation things
	{
		SAXReader reader = new SAXReader();
		try 
	    {
	    	Element root_elm = reader.read(new File(_cfg_location)).getRootElement();
	    	
	    	// code testing
	    	Element debug_elm = (Element) root_elm.selectSingleNode("debug");
	    	_is_debugged = debug_elm.selectSingleNode("@on").getText().equals("true") ? true : false;
	    	
	    	// tfidf
	    	Element tfidf_elm = (Element) root_elm.selectSingleNode("//tfidf");
	    	_tfidf_is_normalized = tfidf_elm.selectSingleNode("@normalized").getText().equals("true") ? true : false;
	    	_tfidf_constant_idf_1 = Double.parseDouble(tfidf_elm.selectSingleNode("@idf_constant_1").getText());
	    	_tfidf_constant_tf_1 = Double.parseDouble(tfidf_elm.selectSingleNode("@tf_constant_1").getText());
	    	_tfidf_constant_tf_2 = Double.parseDouble(tfidf_elm.selectSingleNode("@tf_constant_2").getText());
	    	
	    	// search
	    	Element result_elm = (Element) root_elm.selectSingleNode("//result");
	    	_search_hit_number_per_page = Integer.parseInt(result_elm.selectSingleNode("@hits_per_page").getText());
	    }
	    catch(Exception ex) 
	    {
	    	ex.printStackTrace();
	    }
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////
	
	/**
	 * @return the _is_debugged
	 */
	public static boolean is_debugged()
	{
		return _is_debugged;
	}



	/**
	 * @return the _tfidf_constant_idf_1
	 */
	public static double get_tfidf_constant_idf_1()
	{
		return _tfidf_constant_idf_1;
	}



	/**
	 * @return the _tfidf_constant_tf_1
	 */
	public static double get_tfidf_constant_tf_1()
	{
		return _tfidf_constant_tf_1;
	}



	/**
	 * @return the _tfidf_constant_tf_2
	 */
	public static double get_tfidf_constant_tf_2()
	{
		return _tfidf_constant_tf_2;
	}



	/**
	 * @return the _tfidf_is_normalized
	 */
	public static boolean is_tfidf_is_normalized()
	{
		return _tfidf_is_normalized;
	}


	/**
	 * @return the _search_hit_number_per_page
	 */
	public static int get_search_hit_number_per_page()
	{
		return _search_hit_number_per_page;
	}



	public static void main(String[] args)
	{
		ConfigureCenter cc = new ConfigureCenter();
	}
}
